﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Honestysoft.BaseObject;
using Honestysoft.Financing.Model;
using System.Data;

namespace Honestysoft.Financing.WebUI.Module.Audit
{
    /// <summary>
    /// checkNewPDCD 的摘要说明
    /// </summary>
    public class checkNewPDCD : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string projectCode = context.Request.Params["ProjectCode"];
            string projectName = context.Request.Params["ProjectName"];
            string contractName = context.Request.Params["ContractName"];
            string responseData = "";
            Dictionary<int, string> dicMsg = new Dictionary<int, string>();
            BaseBusinessLogic<BD_Project> bllProject=new BaseBusinessLogic<BD_Project>("");
            BaseBusinessLogic<BD_Contract> bllContract = new BaseBusinessLogic<BD_Contract>("");
            DataTable dt = null;
            QueryParameters query = new QueryParameters();
            query.Add("Code", projectCode, QueryParameters.OperatorType.Equal);
            dt = bllProject.GetTable(query);
            if (dt.Rows.Count > 0)
            {
                dicMsg.Add(dicMsg.Count+1, "系统检测到已经存在项目代码为【" + projectCode + "】的项目，请谨慎处理！");
            }
            query = new QueryParameters();
            query.Add("Name", projectName, QueryParameters.OperatorType.Equal);
            dt = bllProject.GetTable(query);
            if (dt.Rows.Count > 0)
            {
                dicMsg.Add(dicMsg.Count + 1, "系统检测到已经存在项目名称为【" + projectCode + "】的项目，请谨慎处理！");
            }
            query = new QueryParameters();
            query.Add("Name", contractName, QueryParameters.OperatorType.Equal);
            dt = bllContract.GetTable(query);
            if (dt.Rows.Count > 0)
            {
                dicMsg.Add(dicMsg.Count + 1, "系统检测到已经存在合同名称为【" + projectCode + "】的合同，请谨慎处理！");
            }
            if (dicMsg.Count > 0)
            {
                foreach (KeyValuePair<int, string> kv in dicMsg)
                {
                    if (responseData != "") { responseData += "\r\n"; }
                    responseData += kv.Key.ToString() + "." + kv.Value;
                }
            }
            context.Response.Write(context.Server.HtmlEncode(responseData));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}